/////////////////////////////////////////////////////////////////////////////

class LoadingUI extends egret.Sprite {
    public constructor() {
        super();
        this.createView();
    }
    private textField: egret.TextField;

    private createView(): void {

        // //音乐图标
        // // var music_logo = createBitmap("music_logo_png", 80, 50);
        // var music_logo = createBitmap("music_logo_png", 32.5, 32.5);
        // this.addChild(music_logo);
        // music_logo.anchorOffsetX = 65 * .5;
        // music_logo.anchorOffsetY = 65 * .5;
        // var tw = egret.Tween.get(music_logo, { loop: true }).to({ rotation: 360 }, 2000);
        // music_logo.touchEnabled = true;
        // //声音加载
        // var sound = new egret.Sound;
        // var soundChannel;
        // var music_Length = 0;
        // var curTime = 0;
        // sound.addEventListener(egret.Event.COMPLETE, function () {
        //     soundChannel = sound.play(curTime, 0);
        //     music_Length = sound.length;
        // }, this);
        // sound.load("resource/assets/music.mp3");
        // //实现点击music_logo图标播放/暂停功能
        // music_logo.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
        //     if (soundChannel === null) {
        //         soundChannel = sound.play(curTime);
        //         soundChannel.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
        //         })
        //         egret.Tween.resumeTweens(music_logo);
        //     } else {
        //         curTime = soundChannel.position;
        //         soundChannel.stop();
        //         soundChannel = null;
        //         egret.Tween.pauseTweens(music_logo);
        //     }
        // }, this);


        //单独加载资源
        // RES.getResByUrl("resource/assets/LoadingBG.png", function (texture) {
        //     //添加背景
        //     var bg = new egret.Bitmap();
        //     bg.texture = texture;
        //     this.addChildAt(bg, 0);
        // }, this);
        // this.textField = new egret.TextField();
        // this.addChild(this.textField);
        // this.textField.y = 300;
        // this.textField.width = 750;
        // this.textField.textAlign = "center";

        //
        // RES.getResByUrl("resource/assets/bg_ripple.png", function (texture) {
        //     //预加载添加背景
        //     // var bg = new egret.Bitmap();
        //     // bg.texture = texture;
        //     // bg.x = 94;
        //     // this.addChildAt(bg, 10);
        //     var ripple1 = new egret.Bitmap();
        //     ripple1.texture = texture
        //     this.addChild(ripple1,5);
        //     // egret.Tween.get(ripple1, { loop: true }).to({ x: -630 }, 30000);
        // }, this);


        RES.getResByUrl("resource/assets/longdingbg.png", function (texture) {
            //预加载logo图片
            var bg = new egret.Bitmap();
            bg.texture = texture;
            bg.x = 94;
            this.addChild(bg);
        }, this);

        this.textField = new egret.TextField();
        this.addChildAt(this.textField, this.numChildren - 1);
        this.textField.y = 516;
        this.textField.x = 0;
        this.textField.width = 640;
        this.textField.textAlign = "center";
    }

    public setProgress(current: number, total: number): void {

        var percent = Math.ceil(current / total * 100);
        this.textField.text = `Loading...${percent}%`;
//      //进度条背景矩形
//      var jindutiaoBG = new egret.Shape();
//      jindutiaoBG.graphics.beginFill(0x8aacdf);
//      jindutiaoBG.graphics.drawRoundRect(195, 600, 250, 10, 0, 0);
//      jindutiaoBG.graphics.endFill();
//      this.addChildAt(jindutiaoBG, 8);
//      //进度条
//      var jdt = new egret.Shape();
//      jdt.graphics.beginFill(0xf21111);
//      jdt.graphics.drawRoundRect(195, 600, 250 * percent * 0.01, 10, 0, 0);
//      jdt.graphics.endFill();
//      this.addChildAt(jdt, 8);
		//进度条背景矩形
        var jindutiaoBG = new egret.Shape();
        jindutiaoBG.graphics.beginFill(0xCCCCCC);
        // jindutiaoBG.graphics.drawRoundRect(195, 600, 250, 10, 0, 0);
        jindutiaoBG.graphics.drawRect(195, 600, 250, 10);
        jindutiaoBG.graphics.endFill();
        this.addChildAt(jindutiaoBG, 8);
         //进度条
        var jdt = new egret.Shape();
        jdt.graphics.beginFill(0xff0000);
        jdt.graphics.drawRect(195, 605, 250 * percent * 0.01, 10);
        jdt.graphics.endFill();
        this.addChildAt(jdt, 7);


    }

}

//////////////////////////////////////////////////////////////////////////////////////

// class LoadingUI extends egret.Sprite {

//     public constructor() {
//         super();
//         this.createView();
//     }

//     private textField:egret.TextField;

//     private createView():void {
//         this.textField = new egret.TextField();
//         this.addChild(this.textField);
//         this.textField.y = 300;
//         this.textField.width = 480;
//         this.textField.height = 100;
//         this.textField.textAlign = "center";
//     }

//     public setProgress(current:number, total:number):void {
//         this.textField.text = `Loading...${current}/${total}`;
//     }
// }

